package library.web.servlet.page;

import library.domain.Book;
import library.domain.User;
import library.persistence.dao.BookDao;
import library.persistence.impl.BookDaoImpl;
import library.persistence.service.AccountService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;


public class bookDetailsServlet extends HttpServlet {

    public static final String BOOK_DETAILS_PAGE = "/WEB-INF/jsp/bookDetails.jsp";

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //获取点击该条目的BOOKID
        String bookId = req.getParameter("bookId");
        System.out.println(bookId);
        BookDao bookDao = new BookDaoImpl();
        //获取当前点击的book
        Book book=bookDao.getBookByBookId(Integer.parseInt(bookId));
        System.out.println(book);
        //把所有值都放进session中，保持会话连接
        HttpSession session = req.getSession();
        session.setAttribute("book",book);//在会话中放入两个键值对

        req.getRequestDispatcher(BOOK_DETAILS_PAGE).forward(req,resp);

    }
}
